﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using ScormModel;
namespace WpfELearningAuthoringTool
{
    class ContextMenuUtils
    {
        string addLessonPath = "Images/LessonsIcon.png";
        string addContentPath = "Images/PageIcon.png";
        string addModulePath = "Images/AddModuleIcon.png";
        string addQuestionPath = "Images/QuestionIcon.png";
        string viewPropertyPath = "Images/InformationIcon.png";
        string renamePath = "Images/RenameIcon.png";
        string removeItemPath = "Images/RemoveIcon.png";
        string currentDirectory;
        TreeView tvMain;
        ImsManifest imsmanifest;
        StackPanel container;
        WebBrowser browser;
        RibbonBarRegion.RibbonBarHeader parentChild;
        public string CurrentDirectory
        {
            get { return this.currentDirectory; }
            set { this.currentDirectory = value; }
        }
        public WebBrowser WebBrowser
        {
            get { return this.browser; }
            set { this.browser = value; }
        }
        public StackPanel Container
        {
            get { return this.container; }
            set { this.container = value; }
        }
        public ImsManifest Imsmanifest
        {
            get { return this.imsmanifest; }
            set { this.imsmanifest = value; }
        }
        public TreeView MainTree
        {
            get { return this.tvMain; }
            set { this.tvMain = value; }
        }
        public RibbonBarRegion.RibbonBarHeader Parent
        {
            get { return this.parentChild; }
            set { this.parentChild = value; }
        }
        public ContextMenu buildContextMenuForNoneTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.Parent = parentChild;
            cma.CurrentDirectory = currentDirectory;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "RenameCourse";
                renameItem.Click += cma.RenameCourseForNoneTemplate;
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addModulePath, UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForNoneTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "INTRO")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddIntoForNoneTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForNoneTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForNoneTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForNoneTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";             
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForNoneTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForNoneTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddLessonContentForNoneTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "EXAM")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addQuestionPath, UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuestionForNoneTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "QUESTION")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForNoneTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForNoneTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddQuestionContentForNoneTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuForLinearTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "RenameCourse";
                renameItem.Click += cma.RenameCourseForLinearTemplate;
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addModulePath, UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForLinearTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "INTRO")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddIntoForLinearTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForLinearTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForLinearTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForLinearTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForLinearTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForLinearTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddLessonContentForLinearTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "EXAM")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addQuestionPath, UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuestionForLinearTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "QUESTION")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForLinearTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForLinearTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddQuestionContentForLinearTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuForLinearChoiceTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "RenameCourse";
                renameItem.Click += cma.RenameCourseForLinearChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "INTRO")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddIntoForLinearChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULES")
            {
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addModulePath, UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForLinearChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULE")
            {

                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForLinearChoiceTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForLinearChoiceTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForLinearChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForLinearChoiceTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForLinearChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "EXAM")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addQuestionPath, UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuestionForLinearChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "QUESTION")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddQuestionContentForLinearChoiceTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForLinearChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuForLinearControlTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "RenameCourse";
                renameItem.Click += cma.RenameCourseForLinearControlTemplate;
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addModulePath, UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForLinearControlTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "INTRO")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddIntoForLinearControlTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForLinearControlTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonContentForLinearControlTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "EXAM")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addQuestionPath, UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuesionForLinearControlTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "QUESTION")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddLessonContentForLinearControlTemplate; 
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuForConstrainedChoiceTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "RenameCourse";
                renameItem.Click += cma.RenameCourseForConstrainedChoiceTemplate;
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addModulePath, UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForConstrainedChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "INTRO")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddIntoForConstrainedChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            //else if (type == "MODULES")
            //{
            //    MenuItem addModuleItem = new MenuItem();
            //    addModuleItem.Icon = new System.Windows.Controls.Image
            //    {
            //        Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
            //    };
            //    addModuleItem.Header = "Add Module";
            //    addModuleItem.Click += cma.AddModuleForConstrainedChoiceTemplate;
            //    MenuItem propertyItem = new MenuItem();
            //    propertyItem.Icon = new System.Windows.Controls.Image
            //    {
            //        Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
            //    };
            //    propertyItem.Header = "View Propeties";
            //    contextMenu.Items.Add(addModuleItem);
            //    contextMenu.Items.Add(propertyItem);
            //}
            else if (type == "MODULE")
            {

                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForConstrainedChoiceTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForConstrainedChoiceTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForConstrainedChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForConstrainedChoiceTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForConstrainedChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "EXAM")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addQuestionPath, UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuestionForConstrainedChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "QUESTION")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addContentPath, UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddQuestionContentForConstrainedChoiceTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForConstrainedChoiceTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuForCompetencyTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "RenameCourse";
                renameItem.Click += cma.RenameCourseForCompetencyTemplate;
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForCompetencyTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "INTRO")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "PRETEST")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add/Edit Content";
                addContentItem.Click += cma.AddTestContentForCompetencyTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCompetencyTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveModuleItemForCompetencyTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForCompetencyTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCompetencyTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForCompetencyTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "POSTTEST")
            {
                //MenuItem addPartItem = new MenuItem();
                //addPartItem.Icon = new System.Windows.Controls.Image
                //{
                //    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                //};
                //addPartItem.Header = "Add Part";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
             //   contextMenu.Items.Add(addPartItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "PART")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add Questions";
                addQuestionItem.Click += cma.AddQuesionForCompetencyTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "QUESTION")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCompetencyTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForCompetencyTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddQuestionContentForCompetencyTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuForKnowledgePacedTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameCourseForKnowledgePacedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "INTRO")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULES")
            {
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForKnowledgePacedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForKnowledgePacedTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForKnowledgePacedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSONS")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForKnowledgePacedTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForKnowledgePacedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "PRETEST")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuesionForKnowledgePacedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "POSTTEST")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuesionForKnowledgePacedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForKnowledgePacedTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForKnowledgePacedTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "SUMMARY")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add/Edit Content";
                addQuestionItem.Click += cma.GenerateSummaryForKnowledgePacedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "QUESTION")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForKnowledgePacedTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddQuestionContentForKnowledgePacedTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForKnowledgePacedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuForKnowledgePacedReusedTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameCourseForKnowledgePacedReusedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "INTRO")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULES")
            {
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForKnowledgePacedReusedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForKnowledgePacedReusedTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForKnowledgePacedReusedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSONS")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForKnowledgePacedReusedTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForKnowledgePacedReusedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "PRETEST")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuesionForKnowledgePacedReusedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "POSTTEST")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuesionForKnowledgePacedReusedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForKnowledgePacedReusedTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForKnowledgePacedReusedTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "SUMMARY")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add/Edit Content";
                addQuestionItem.Click += cma.GenerateSummaryForKnowledgePacedReusedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "QUESTION")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForKnowledgePacedReusedTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                addContentItem.Click += cma.AddQuestionContentForKnowledgePacedReusedTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForKnowledgePacedReusedTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuForRemediationTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameCourseForCompetencyTemplate;
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForRemediationTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "INTRO")
            {
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "REMEDIATE_MODULE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCompetencyTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addLessonItem.Header = "Add Remediate Lesson";
                addLessonItem.Click += cma.AddLessonForRemediationTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "REMEDIATE_LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCompetencyTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Add Content";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "MODULE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCompetencyTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForRemediationTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForRemediationTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCompetencyTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Remove";
                addContentItem.Click += cma.RemoveItemForCompetencyTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "FIRST_EXAM")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add Part";
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "FINAL_EXAM")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add Part";
                addQuestionItem.Click += cma.AddLessonForRemediationTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "PART")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCompetencyTemplate;
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuestionForRemediationTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(propertyItem);
            }
            else if (type == "QUESTION")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCompetencyTemplate;
                MenuItem addContentItem = new MenuItem();
                addContentItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                addContentItem.Header = "Remove";
                addContentItem.Click += cma.RemoveItemForCompetencyTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addContentItem);
                contextMenu.Items.Add(propertyItem);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuForCustomTemplate(string type)
        {
            ContextMenu contextMenu = new ContextMenu();
            ContextMenuAction cma = new ContextMenuAction();
            cma.Imsmanifest = imsmanifest;
            cma.MainTree = tvMain;
            cma.Container = container;
            cma.Parent = parentChild;
            cma.CurrentDirectory = currentDirectory;
            cma.WebBrowser = browser;
            if (type == "COURSE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "RenameCourse";
                renameItem.Click += cma.RenameCourseForCustomTemplate;
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addModulePath, UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForCustomTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForCustomTemplate;
                MenuItem addTestItem = new MenuItem();
                addTestItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addTestItem.Header = "Add Test";
                addTestItem.Click += cma.AddTestForCustomTemplate;
                MenuItem addExamItem = new MenuItem();
                addExamItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addExamItem.Header = "Add Exam";
                addExamItem.Click += cma.AddExamForCustomTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                MenuItem sequencingConfig = new MenuItem();
                sequencingConfig.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                sequencingConfig.Header = "Course Sequencing Configuration";
                sequencingConfig.Click += cma.ConfigCourseSequencing;

                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(addTestItem);
                contextMenu.Items.Add(addExamItem);
                contextMenu.Items.Add(propertyItem);
                contextMenu.Items.Add(sequencingConfig);
            }
            else if (type == "MODULE")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCustomTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForCustomTemplate;
                MenuItem addLessonItem = new MenuItem();
                addLessonItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addLessonItem.Header = "Add Lesson";
                addLessonItem.Click += cma.AddLessonForCustomTemplate;
                MenuItem addModuleItem = new MenuItem();
                addModuleItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addModulePath, UriKind.Relative))
                };
                addModuleItem.Header = "Add Module";
                addModuleItem.Click += cma.AddModuleForCustomTemplate;
                MenuItem addTestItem = new MenuItem();
                addTestItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addTestItem.Header = "Add Test";
                addTestItem.Click += cma.AddTestForCustomTemplate;
                MenuItem addExamItem = new MenuItem();
                addExamItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                addExamItem.Header = "Add Exam";
                addExamItem.Click += cma.AddExamForCustomTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                MenuItem sequencingConfig = new MenuItem();
                sequencingConfig.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                sequencingConfig.Header = "Sequencing Configuration";
                sequencingConfig.Click += cma.ConfigSequencing;
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(addLessonItem);
                contextMenu.Items.Add(addModuleItem);
                contextMenu.Items.Add(addTestItem);
                contextMenu.Items.Add(addExamItem);
                contextMenu.Items.Add(propertyItem);
                contextMenu.Items.Add(sequencingConfig);
            }
            else if (type == "LESSON")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addLessonPath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCustomTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForCustomTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                MenuItem sequencingConfig = new MenuItem();
                sequencingConfig.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                sequencingConfig.Header = "Time Config";
                sequencingConfig.Click += cma.ConfigTimeLimit;

                MenuItem sequencingConfig1 = new MenuItem();
                sequencingConfig1.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                sequencingConfig1.Header = "Sequencing Configuration";
                sequencingConfig1.Click += cma.ConfigSequencing;

                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
                contextMenu.Items.Add(sequencingConfig);
                contextMenu.Items.Add(sequencingConfig1);
            }
            else if (type == "EXAM")
            {
                MenuItem addQuestionItem = new MenuItem();
                addQuestionItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(addQuestionPath, UriKind.Relative))
                };
                addQuestionItem.Header = "Add Question";
                addQuestionItem.Click += cma.AddQuestionForCustomTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForCustomTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "View Propeties";
                MenuItem sequencingConfig = new MenuItem();
                sequencingConfig.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                sequencingConfig.Header = "Sequencing Configuration";
                sequencingConfig.Click += cma.ConfigSequencing;
                contextMenu.Items.Add(addQuestionItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
                contextMenu.Items.Add(sequencingConfig);
            }
            else if (type == "QUESTION")
            {
                MenuItem renameItem = new MenuItem();
                renameItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                renameItem.Header = "Rename";
                renameItem.Click += cma.RenameNodeForCustomTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForCustomTemplate;
                MenuItem propertyItem = new MenuItem();
                propertyItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                propertyItem.Header = "Add/Edit Content";
                propertyItem.Click += cma.AddQuestionContentForCustomTemplate;
                MenuItem sequencingConfig = new MenuItem();
                sequencingConfig.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                sequencingConfig.Header = "Time Config";
                sequencingConfig.Click += cma.ConfigTimeLimit;
                contextMenu.Items.Add(renameItem);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(propertyItem);
                contextMenu.Items.Add(sequencingConfig);
            }
            else if (type == "TEST")
            {
                MenuItem addTest = new MenuItem();
                addTest.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(renamePath, UriKind.Relative))
                };
                addTest.Header = "Add/Edit Test";
                addTest.Click += cma.AddTestContentForCustomTemplate;
                MenuItem removeItem = new MenuItem();
                removeItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(removeItemPath, UriKind.Relative))
                };
                removeItem.Header = "Remove";
                removeItem.Click += cma.RemoveItemForCustomTemplate;
                MenuItem sequencingConfig = new MenuItem();
                sequencingConfig.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri(viewPropertyPath, UriKind.Relative))
                };
                sequencingConfig.Header = "Sequencing Configuration";
                sequencingConfig.Click += cma.ConfigSequencing;

                contextMenu.Items.Add(addTest);
                contextMenu.Items.Add(removeItem);
                contextMenu.Items.Add(sequencingConfig);
            }
            else
            {
                MenuItem undefineItem = new MenuItem();
                undefineItem.Icon = new System.Windows.Controls.Image
                {
                    Source = new BitmapImage(new Uri("Images/Add.png", UriKind.Relative))
                };
                undefineItem.Header = "Undefine";
                contextMenu.Items.Add(undefineItem);
            }
            return contextMenu;
        }
        public ContextMenu buildContextMenuByTypeOfItem(string type, string template)
        {
            ContextMenu contextMenu = new ContextMenu();
            switch (template)
            {
                case "None":
                    contextMenu = buildContextMenuForNoneTemplate(type);
                    break;
                case "Linear":
                    contextMenu = buildContextMenuForLinearTemplate(type);
                    break;
                case "Linear_Choice":
                    contextMenu = buildContextMenuForLinearChoiceTemplate(type);
                    break;
                case "Linear_Controls":
                    contextMenu = buildContextMenuForLinearControlTemplate(type);
                    break;
                case "Constrained_Choice":
                    contextMenu = buildContextMenuForConstrainedChoiceTemplate(type);
                    break;
                case "Competency":
                    contextMenu = buildContextMenuForCompetencyTemplate(type);
                    break;
                case "KnowledgePaced":
                    contextMenu = buildContextMenuForKnowledgePacedTemplate(type);
                    break;
                case "KnowledgePaced_Reuse":
                    contextMenu = buildContextMenuForKnowledgePacedReusedTemplate(type);
                    break;
                case "Remediation":
                    contextMenu = buildContextMenuForRemediationTemplate(type);
                    break;
                case "Custom":
                    contextMenu = buildContextMenuForCustomTemplate(type);
                    break;
                default:
                    break;
            }
            return contextMenu;
        }

    }
}
